package com.atguigu04.example.exer5_objarr1;

/**
 * @ClassName: Util
 * @Package: com.atguigu04.example.exer5_objarr1
 * @Description:
 * @Author 张居然
 * @Create 2024/1/13 20:45
 * @Version 1.0
 */
public class Util {
    /**
     * 打印全部学生信息
     * @param students
     */
    public void printStudentInfo(Student[] students) {
        for (Student st : students) {
            System.out.println(st.show());
        }
    }

    /**
     * 打印某年级的学生信息
     * @param students
     * @param state
     */
    public void printStudentWithState(Student[] students,int state) {
        for (Student st : students) {
            if(st.state == state)
                System.out.println(st.show());
        }
    }

    /**
     * 依照学生成绩的高低对学生信息排序
     * @param students
     */
    public void studentSort(Student[] students) {
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0;j < students.length - i - 1;j++) {
                if (students[j].score > students[j+1].score){
                    Student temp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = temp;
                }
            }
        }
    }
}
